<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Projet Jetpack:  Fichier source de /home/p1006250/lif7-projet-jetpack/src/Sprite.c</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Projet Jetpack
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Généré par Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Page&#160;principale</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Fichiers</span></a></li>
      <li><a href="dirs.html"><span>Répertoires</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Liste&#160;des&#160;fichiers</span></a></li>
      <li><a href="globals.html"><span>Membres&#160;de&#160;fichier</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_sprite_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Sprite.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_sprite_8c.html">Aller à la documentation de ce fichier.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="_sprite_8h.html">Sprite.h</a>&quot;</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 
<a name="l00004"></a><a class="code" href="_sprite_8h.html#a4b649c7fe373641fefdc8c50f1170c57">00004</a> <a class="code" href="struct_sprite.html">Sprite</a>* <a class="code" href="_sprite_8c.html#a4b649c7fe373641fefdc8c50f1170c57" title=" Brief Description  Initialise un sprite.  ">InitialiserSprite</a>(<a class="code" href="struct_sprite.html">Sprite</a> * pSprite, <span class="keywordtype">int</span> x,<span class="keywordtype">int</span> y,<span class="keywordtype">int</span> w,<span class="keywordtype">int</span> h,<a class="code" href="structs_terrain.html">Terrain</a>* pTer)
<a name="l00005"></a>00005 {
<a name="l00006"></a>00006     pSprite=(<a class="code" href="struct_sprite.html">Sprite</a>*)malloc(<span class="keyword">sizeof</span>(<a class="code" href="struct_sprite.html">Sprite</a>));
<a name="l00007"></a>00007     pSprite-&gt;pPer=(<a class="code" href="struct_personnage.html">Personnage</a>*)malloc(<span class="keyword">sizeof</span>(<a class="code" href="struct_personnage.html">Personnage</a>));
<a name="l00008"></a>00008         pSprite-&gt;pPer-&gt;posX = x;
<a name="l00009"></a>00009         pSprite-&gt;pPer-&gt;posY = y;
<a name="l00010"></a>00010         pSprite-&gt;pPer-&gt;w = w;
<a name="l00011"></a>00011         pSprite-&gt;pPer-&gt;h = h;
<a name="l00012"></a>00012         pSprite-&gt;pTer = pTer;
<a name="l00013"></a>00013         <span class="keywordflow">return</span> pSprite;
<a name="l00014"></a>00014 }
<a name="l00015"></a>00015 
<a name="l00016"></a><a class="code" href="_sprite_8h.html#affba9d86f8ae9fe08348877045147d9f">00016</a> <span class="keywordtype">int</span> <a class="code" href="_sprite_8c.html#affba9d86f8ae9fe08348877045147d9f" title=" Brief Description  Met à jour le scrolling.  ">UpdateScroll</a>(<a class="code" href="structs_terrain.html">Terrain</a>* pTer, <a class="code" href="struct_sprite.html">Sprite</a> * pSprite)
<a name="l00017"></a>00017 {
<a name="l00018"></a>00018         <span class="keywordtype">int</span> cxperso,xlimmin,xlimmax;
<a name="l00019"></a>00019     <span class="keywordflow">if</span> (pTer-&gt;<a class="code" href="structs_terrain.html#a276723ce5e13846eaf00445cf0206b54">focusSprite</a>==NULL)
<a name="l00020"></a>00020                 <span class="keywordflow">return</span> -1;
<a name="l00021"></a>00021         cxperso = pTer-&gt;<a class="code" href="structs_terrain.html#a276723ce5e13846eaf00445cf0206b54">focusSprite</a>-&gt;pPer-&gt;posX + pTer-&gt;<a class="code" href="structs_terrain.html#a276723ce5e13846eaf00445cf0206b54">focusSprite</a>-&gt;pPer-&gt;w/2;
<a name="l00022"></a>00022         xlimmin = pTer-&gt;<a class="code" href="structs_terrain.html#a5692b40e1e9677764b6da00a4c2c24e9">xscroll</a> + pTer-&gt;<a class="code" href="structs_terrain.html#a8211b66a78c1e426bc98908431d40bcf">focusx</a>;
<a name="l00023"></a>00023         xlimmax = xlimmin + pTer-&gt;<a class="code" href="structs_terrain.html#af9815df6b8a253e3db89b907f4a1198f">focusw</a>;
<a name="l00024"></a>00024         <span class="keywordflow">if</span> (cxperso&lt;xlimmin)
<a name="l00025"></a>00025                 pTer-&gt;<a class="code" href="structs_terrain.html#a5692b40e1e9677764b6da00a4c2c24e9">xscroll</a> -= (xlimmin-cxperso);
<a name="l00026"></a>00026         <span class="keywordflow">if</span> (cxperso&gt;xlimmax)
<a name="l00027"></a>00027                 pTer-&gt;<a class="code" href="structs_terrain.html#a5692b40e1e9677764b6da00a4c2c24e9">xscroll</a> += (cxperso-xlimmax);
<a name="l00028"></a>00028         <span class="keywordflow">return</span> 0;
<a name="l00029"></a>00029 }
<a name="l00030"></a>00030 
<a name="l00031"></a><a class="code" href="_sprite_8h.html#ac89376e6e2a55b15702b26eaac32a676">00031</a> <span class="keywordtype">int</span> <a class="code" href="_sprite_8c.html#a6386c317dab4e793e117656d019376aa" title=" Brief Description  Libere la mémoire allouée. ">LibereSprite</a>(<a class="code" href="struct_sprite.html">Sprite</a>* pSprite)
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033         free(pSprite);
<a name="l00034"></a>00034         <span class="keywordflow">return</span> 0;
<a name="l00035"></a>00035 }
<a name="l00036"></a>00036 
<a name="l00037"></a><a class="code" href="_sprite_8h.html#ad30c5c0a1c1fc518ef81d052d549a154">00037</a> <span class="keywordtype">int</span> <a class="code" href="_sprite_8c.html#a41e42de1a10a407b6eca7aaa3ea90d6c" title=" Brief Description  Test la collision.  ">CollisionDecors</a>(<a class="code" href="struct_sprite.html">Sprite</a>* pSprite)
<a name="l00038"></a>00038 {
<a name="l00039"></a>00039         <span class="keywordtype">int</span> xmin,xmax,ymin,ymax,i,j,indicetile;
<a name="l00040"></a>00040         <a class="code" href="structs_terrain.html">Terrain</a>* pTer = pSprite-&gt;pTer;
<a name="l00041"></a>00041         <span class="keywordflow">if</span> (pSprite-&gt;pPer-&gt;posX&lt;0 || pSprite-&gt;pPer-&gt;posY&lt;0 || (pSprite-&gt;pPer-&gt;posY + pSprite-&gt;pPer-&gt;h -1)&gt;=pTer-&gt;<a class="code" href="structs_terrain.html#ab27a7bca0b8d1bfd8c501b0b8b4c6e69">nbtiles_hauteur_monde</a>*pTer-&gt;<a class="code" href="structs_terrain.html#add63ba136dabd9690e18e14258093f16">HAUTEUR_TILE</a>) <span class="comment">// Test si le personnage ne sort pas du monde</span>
<a name="l00042"></a>00042                 <span class="keywordflow">return</span> 1;
<a name="l00043"></a>00043         xmin = pSprite-&gt;pPer-&gt;posX / pTer-&gt;<a class="code" href="structs_terrain.html#ab958ea78e1078769b3e02c1618b5c015">LARGEUR_TILE</a>; <span class="comment">// Le x minimum de notre boite englobante.</span>
<a name="l00044"></a>00044         ymin = pSprite-&gt;pPer-&gt;posY / pTer-&gt;<a class="code" href="structs_terrain.html#add63ba136dabd9690e18e14258093f16">HAUTEUR_TILE</a>; <span class="comment">// Le y minimum de notre boite englobante.</span>
<a name="l00045"></a>00045         xmax = (pSprite-&gt;pPer-&gt;posX + pSprite-&gt;pPer-&gt;w -1) / pTer-&gt;<a class="code" href="structs_terrain.html#ab958ea78e1078769b3e02c1618b5c015">LARGEUR_TILE</a>; <span class="comment">// Le x maximum de notre boite englobante.</span>
<a name="l00046"></a>00046         ymax = (pSprite-&gt;pPer-&gt;posY + pSprite-&gt;pPer-&gt;h -1) / pTer-&gt;<a class="code" href="structs_terrain.html#add63ba136dabd9690e18e14258093f16">HAUTEUR_TILE</a>; <span class="comment">// Le y maximum de notre boite englobante.</span>
<a name="l00047"></a>00047         <span class="keywordflow">for</span>(i=xmin;i&lt;=xmax;i++)
<a name="l00048"></a>00048         {
<a name="l00049"></a>00049                 <span class="keywordflow">for</span>(j=ymin;j&lt;=ymax;j++)
<a name="l00050"></a>00050                 {
<a name="l00051"></a>00051                         indicetile = pTer-&gt;<a class="code" href="structs_terrain.html#a8ee104dd02c94a9fdbba663441b4d2da">schema</a>[i%pTer-&gt;<a class="code" href="structs_terrain.html#af4ffcf044ec7b408dbad1fbb981de1c9">nbtiles_largeur_monde</a>][j];
<a name="l00052"></a>00052                         <span class="keywordflow">if</span> (pTer-&gt;<a class="code" href="structs_terrain.html#afd885af4967004f679bcfbe9bcf7e14f">tileplein</a>[indicetile]==1)
<a name="l00053"></a>00053                         {
<a name="l00054"></a>00054                                 <span class="keywordflow">return</span> 1;
<a name="l00055"></a>00055                         }
<a name="l00056"></a>00056         }
<a name="l00057"></a>00057         }
<a name="l00058"></a>00058         <span class="keywordflow">return</span> 0;
<a name="l00059"></a>00059 }
<a name="l00060"></a>00060 
<a name="l00061"></a><a class="code" href="_sprite_8h.html#a75aa6342b3d5192493d1daef6133be11">00061</a> <span class="keywordtype">int</span> <a class="code" href="_sprite_8c.html#a8f37e5a75884af1c0c38a4caf9130092" title=" Brief Description  Test si un déplacement est possible.  ">EssaiDeplacement</a>(<a class="code" href="struct_sprite.html">Sprite</a>* pSprite,<span class="keywordtype">int</span> vx,<span class="keywordtype">int</span> vy)
<a name="l00062"></a>00062 {
<a name="l00063"></a>00063         <a class="code" href="struct_sprite.html">Sprite</a> test;
<a name="l00064"></a>00064         test = *pSprite;
<a name="l00065"></a>00065         test.pPer-&gt;posX+=vx;
<a name="l00066"></a>00066         test.pPer-&gt;posY+=vy;
<a name="l00067"></a>00067         <span class="keywordflow">if</span> (<a class="code" href="_sprite_8c.html#a41e42de1a10a407b6eca7aaa3ea90d6c" title=" Brief Description  Test la collision.  ">CollisionDecors</a>(&amp;test)==0)
<a name="l00068"></a>00068         {
<a name="l00069"></a>00069                 *pSprite = test;
<a name="l00070"></a>00070                 <span class="keywordflow">return</span> 1;
<a name="l00071"></a>00071         }
<a name="l00072"></a>00072         <span class="keywordflow">return</span> 0;
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074 
<a name="l00075"></a><a class="code" href="_sprite_8h.html#aef762179d867febc430bff4af2267885">00075</a> <span class="keywordtype">void</span> <a class="code" href="_sprite_8c.html#af9dedf702925d0d52c312f7a1b228144" title=" Brief Description  Affine la collision. ">Affine</a>(<a class="code" href="struct_sprite.html">Sprite</a>* pSprite,<span class="keywordtype">int</span> vx,<span class="keywordtype">int</span> vy)
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077         <span class="keywordtype">int</span> i;
<a name="l00078"></a>00078         <span class="keywordflow">for</span>(i=0;i&lt;<a class="code" href="_sprite_8h.html#adefab4344518e9d35a80d87c20c0fa48">ABS</a>(vx);i++)
<a name="l00079"></a>00079         {
<a name="l00080"></a>00080                 <span class="keywordflow">if</span> (<a class="code" href="_sprite_8c.html#a8f37e5a75884af1c0c38a4caf9130092" title=" Brief Description  Test si un déplacement est possible.  ">EssaiDeplacement</a>(pSprite,<a class="code" href="_sprite_8h.html#a3af35b2f3ecf099e959f98d3aaa558a5">SGN</a>(vx),0)==0)
<a name="l00081"></a>00081                         <span class="keywordflow">break</span>;
<a name="l00082"></a>00082         }
<a name="l00083"></a>00083         <span class="keywordflow">for</span>(i=0;i&lt;<a class="code" href="_sprite_8h.html#adefab4344518e9d35a80d87c20c0fa48">ABS</a>(vy);i++)
<a name="l00084"></a>00084         {
<a name="l00085"></a>00085                 <span class="keywordflow">if</span> (<a class="code" href="_sprite_8c.html#a8f37e5a75884af1c0c38a4caf9130092" title=" Brief Description  Test si un déplacement est possible.  ">EssaiDeplacement</a>(pSprite,0,<a class="code" href="_sprite_8h.html#a3af35b2f3ecf099e959f98d3aaa558a5">SGN</a>(vy))==0)
<a name="l00086"></a>00086                         <span class="keywordflow">break</span>;
<a name="l00087"></a>00087         }
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00090"></a><a class="code" href="_sprite_8h.html#ac34d3c8ac9dec7b99115100381c896e6">00090</a> <span class="keywordtype">int</span> <a class="code" href="_sprite_8c.html#aac6a72bc14350b6bd51616dba329fe1d" title=" Brief Description  Test si les déplacements sont possibles.  ">DeplaceSprite</a>(<a class="code" href="struct_sprite.html">Sprite</a>* pSprite,<span class="keywordtype">int</span> vx,<span class="keywordtype">int</span> vy)
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092         <span class="keywordflow">if</span> (vx&gt;=pSprite-&gt;pTer-&gt;LARGEUR_TILE || vy&gt;=pSprite-&gt;pTer-&gt;HAUTEUR_TILE)
<a name="l00093"></a>00093         {
<a name="l00094"></a>00094                 <a class="code" href="_sprite_8c.html#aac6a72bc14350b6bd51616dba329fe1d" title=" Brief Description  Test si les déplacements sont possibles.  ">DeplaceSprite</a>(pSprite,vx-vx/2,vy-vy/2);<span class="comment">// Si vx ou vy trop grand, on relance la fonction avec des vecteurs deux fois plus petit</span>
<a name="l00095"></a>00095                 <span class="keywordflow">return</span> 0;
<a name="l00096"></a>00096         }
<a name="l00097"></a>00097         <span class="keywordflow">if</span> (<a class="code" href="_sprite_8c.html#a8f37e5a75884af1c0c38a4caf9130092" title=" Brief Description  Test si un déplacement est possible.  ">EssaiDeplacement</a>(pSprite,vx,vy)==1)
<a name="l00098"></a>00098                 <span class="keywordflow">return</span> 0;
<a name="l00099"></a>00099         <a class="code" href="_sprite_8c.html#af9dedf702925d0d52c312f7a1b228144" title=" Brief Description  Affine la collision. ">Affine</a>(pSprite,vx,vy);
<a name="l00100"></a>00100         <span class="keywordflow">return</span> 0;
<a name="l00101"></a>00101 }
<a name="l00102"></a>00102 
<a name="l00103"></a><a class="code" href="_sprite_8h.html#a519d35f4b42cc5764208777e7838e6ed">00103</a> <span class="keywordtype">int</span> <a class="code" href="_sprite_8c.html#a74d0672b51f6223f75d4327e049d4b17" title=" Brief Description  Test si le personnage est mort(fin de partie).  ">persMort</a>(<a class="code" href="struct_sprite.html">Sprite</a> * pSprite, <span class="keywordtype">int</span> vx, <span class="keywordtype">int</span> vy)
<a name="l00104"></a>00104 {
<a name="l00105"></a>00105     <a class="code" href="_sprite_8c.html#a8f37e5a75884af1c0c38a4caf9130092" title=" Brief Description  Test si un déplacement est possible.  ">EssaiDeplacement</a>(pSprite,vx,vy);
<a name="l00106"></a>00106 
<a name="l00107"></a>00107     <span class="keywordflow">if</span>(<a class="code" href="_sprite_8c.html#a8f37e5a75884af1c0c38a4caf9130092" title=" Brief Description  Test si un déplacement est possible.  ">EssaiDeplacement</a>(pSprite,vx,vy)==0)
<a name="l00108"></a>00108     {
<a name="l00109"></a>00109         <span class="keywordflow">return</span> 1;
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111     <span class="keywordflow">return</span> 0;
<a name="l00112"></a>00112 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_sprite_8c.html">Sprite.c</a>      </li>

    <li class="footer">Généré le Lundi Décembre 17 2012 01:09:40 pour Projet Jetpack par
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
